package com.dimples.dd.redis.core.receiver;

import cn.hutool.core.util.ObjectUtil;
import com.dimples.dd.common.spring.SpringContextHolder;
import com.dimples.dd.redis.core.constant.RedisConstants;
import com.dimples.dd.redis.core.listener.RedisListener;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/9/14
 */
@Component
@Data
public class RedisReceiver {

    /**
     * 接受消息并调用业务逻辑处理器
     *
     * @param params 消息
     */
    public void onMessage(Map<String, Object> params) {
        Object handlerName = params.get(RedisConstants.HANDLER_NAME);
        RedisListener messageListener = SpringContextHolder.getHandler(handlerName.toString(), RedisListener.class);
        if (ObjectUtil.isNotEmpty(messageListener)) {
            messageListener.onMessage(params);
        }
    }

}
